<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="选择身份源" width="1100px" showFooter destroy-on-close @ok="handleSubmit">
    <BasicTable @register="registerTable">
      
    </BasicTable>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, computed, unref, onMounted, nextTick } from "vue"
  import { JDictSelectTag } from "/@/components/Form"
  import { BasicModal, useModal, useModalInner } from "/@/components/Modal"
  import * as extIdpApi from "/@/api/iam/extIdp"
  import { useMessage } from "/@/hooks/web/useMessage"
  import { BasicTable, useTable, BasicTableProps } from '/@/components/Table';
  import { columns } from "./data"
  type Key = string | number;
  
  const { createMessage } = useMessage()
  const fieldTableRef = ref()

  const emit = defineEmits(["success", "register"])

  const loading = ref(false)

  const selectedRowKeys = ref<any[]>([])

  const tableProps: BasicTableProps = {
    title: "身份源列表",
    bordered: false,
    rowSelection:  {
      type: 'radio',
      columnWidth: 45,
      selectedRowKeys: selectedRowKeys as unknown as Key[],
      onChange: (_selectedRowKeys: Key[], selectedRows: Recordable[]) => {
        selectedRowKeys.value = _selectedRowKeys;
      },
    },
    rowKey: 'id',
    api: extIdpApi.pageIdpTmpl,
    showIndexColumn: false,
    useSearchForm: false,
    columns: columns,
    canResize: false
  };

  const [registerTable, { reload, getForm, clearSelectedRowKeys }] = useTable(tableProps)
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    clearSelectedRowKeys()
    setModalProps({ 
      canFullscreen: true,
      defaultFullscreen: false,
    })
    
  })

  async function handleSubmit(exit) {
    closeModal()
    if (selectedRowKeys.value.length == 0) {
      return
    }
    emit("success", selectedRowKeys.value[0])
  }
</script>
